package nz.co.doherty.gwtpbreadcrumbs.client.ui.home;

import nz.co.doherty.gwtpbreadcrumbs.client.i8n.ClientConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.philbeaudoin.gwtp.mvp.client.ViewImpl;


public class HomeViewImpl extends ViewImpl implements HomeView {

	interface Binder extends UiBinder<Widget, HomeViewImpl> {
	}

	private static Binder binder = GWT
			.create(Binder.class);

	Widget widget;
	
	@UiField
	Hyperlink listProducts;
	
	@UiField
	Hyperlink listCustomers;
	
	@UiField
	Hyperlink listOrders;

	@UiField
	Button reset;

	private Provider<Presenter> presenterProvider;
	
	@Inject
	public HomeViewImpl(ClientConstants constants, Provider<HomeView.Presenter> presenterProvider) {
		widget = binder.createAndBindUi(this);
		this.presenterProvider = presenterProvider;
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setListCustomersToken(String token) {
		this.listCustomers.setTargetHistoryToken(token);		
	}

	@Override
	public void setListOrdersToken(String token) {
		this.listOrders.setTargetHistoryToken(token);		
	}

	@Override
	public void setListProductsToken(String token) {
		this.listProducts.setTargetHistoryToken(token);		
	}
	
	@UiHandler("reset")
	public void onReset(ClickEvent event) {
		presenterProvider.get().onResetData();
	}

}
